const mongoose = require('mongoose')

const hostname ='0.0.0.0'
const port = 27017
const dbname = 'Slibrary'



const CONN_DB_URL = `mongodb://${hostname}:${port}/${dbname}`
console.log(CONN_DB_URL);

mongoose.connect(CONN_DB_URL,{
    useNewUrlParser:true,
    useUnifiedTopology:true
},err=>{

    if(err){
        console.log('数据库连接异常');
    }else{
        console.log('数据库连接成功');
    }
})

mongoose.connection.on('connected',function(){
    console.log("Mongoose connection open to" + CONN_DB_URL);
})

//连接异常
mongoose.connection.on('error',function(err){
    console.log("Mongoose connection open to" + err);
})

// 连接断开
mongoose.connection.on('disconnected',function(){
    console.log("Mongoose connection disconnected");
})
